package com.settlement.system.converter;

import com.alibaba.excel.converters.string.StringStringConverter;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.ReadCellData;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import org.apache.commons.lang3.StringUtils;

/**
 * 是否
 *
 * @author Ximi
 * @since 2020/12/15
 */
public class YesOrNoConverter extends StringStringConverter {

    @Override
    public WriteCellData convertToExcelData(String value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
        if (value != null) {
            if (value.equals("1")) {
                return new WriteCellData("是");
            } else if (value.equals("0")) {
                return new WriteCellData("否");
            }
        }
        return super.convertToExcelData(value, contentProperty, globalConfiguration);
    }

    @Override
    public String convertToJavaData(ReadCellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
        String value = super.convertToJavaData(cellData, contentProperty, globalConfiguration);
        if(!StringUtils.isEmpty(value)){
            if (value.equals("是")) {
                return "1";
            } else if (value.equals("否")) {
                return "0";
            }
        }
        return null;
    }
}
